
//
//  DisCountWebViewController.m
//  GoShops
//
//  Created by zcj on 15-11-30.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "DisCountWebViewController.h"
#import "Grouble.h"
#import "MBProgressHUD+MJ.h"

@interface DisCountWebViewController ()<UIWebViewDelegate>
@end

@implementation DisCountWebViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    [self setWebView];
    // Do any additional setup after loading the view.
}
- (void)setWebView
{
    self.uiwebView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    self.uiwebView.delegate = self;
    self.uiwebView.scalesPageToFit = YES;
    [self.view addSubview:self.uiwebView];
    
    NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.webStr]];
    
    [self.uiwebView loadRequest:request];
    
    _activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(ScreenWidth/2-15, ScreenHeight/2-15, 30, 30)];
    _activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    _activityView.hidesWhenStopped = YES;
    [self.view addSubview:_activityView];
    [self.view bringSubviewToFront:_activityView];
    
}

#pragma mark - 开始加载
- (void)webViewDidStartLoad:(UIWebView *)webView
{
     [_activityView startAnimating];
    [MBProgressHUD showMessage:@"正在加载"];
}

#pragma mark - 加载成功
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [MBProgressHUD hideHUD];
    [MBProgressHUD showSuccess:@"加载成功"];
    [_activityView stopAnimating];
    
    NSString *theTitle=[webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    ZCJLog(@"%@",theTitle);
    self.title = theTitle;
    
}
#pragma mark - 加载失败
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [MBProgressHUD showError:@"加载失败"];
   
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
